<?php

class ParserConfiguration {

    public static function getAction($p_action) {
        return self::parseConf($p_action);
    }

    private static function parseConf($p_action) {
        $xmlArbo = simplexml_load_file('./application/application.xml');

        $actions = $xmlArbo->children();

        $page = null;

        foreach ($actions->children() as $parse) {

            if ((string) $parse['name'] == $p_action) {
                $page = new PageDescription((string) $parse['name'], (string) $parse['isPrivee']);

                if (isset($parse['create'])) {
                    Logger::getInstance()->addLogMessage('Controller create:' . $parse['create']);
                    $page->setCreateService((string) $parse['create']);
                }

                if (isset($parse['update'])) {
                    $page->setUpdateService((string) $parse['update']);
                    Logger::getInstance()->addLogMessage('Controller update:' . $parse['update']);
                }

                if (isset($parse['delete'])) {
                    $page->setDeleteService((string) $parse['delete']);
                    Logger::getInstance()->addLogMessage('Controller delete:' . $parse['delete']);
                }

                if (isset($parse['display'])) {
                    $page->setDisplayService((string) $parse['display']);
                    Logger::getInstance()->addLogMessage('Controller display:' . $parse['display']);
                } else {
                    die('une page doit comporter au moins une action display!!!');
                }
                
                if (isset($parse['render'])) {
                    $page->setRender((string) $parse['render']);
                }

                if (isset($parse['paramFlow'])) {
                    $page->paramFlow((string) $parse['paramFlow']);
                    Logger::getInstance()->addLogMessage('Flux:' . $parse['paramFlow']);
                }

                $page->setXslFile($parse['xsl']);
                $page->setPrivee($parse['isPrivee']);
            }
        }
        return $page;
    }

}

?>
